// 用于拼接字符串（自动插入换行）并替换到代码文件的类
function myString(dfText) {
    this.val = dfText || ''
    this.add = text => (this.val += (text || '') + '\r\n')
    this.writeTo = (strCode,tag) => {
        return strCode.replace(new RegExp(`\\@${tag},?`, 'g'), this.val.trimLeft())
    }
}

export const generatorDto = (setting,temp)=>{

    let strCode = temp
    temp = null

    strCode = strCode.replace('@Namespace',setting.namespace.entity)
    strCode = strCode.replace('@ProjectName',`${setting.project.f_Name}-${setting.moduleName}`)
    strCode = strCode.replace('@CompanyName',setting.company)
    strCode = strCode.replace('@CreateUserName',setting.userInfo.f_RealName)
    strCode = strCode.replace('@Datetime',setting.createTime)
    strCode = strCode.replace('@Des',`${setting.des}表单提交参数`)
    strCode = strCode.replace('@ClassName',window.$upFirst(`${setting.name}Dto`))

    let content = new myString()
    setting.dbTable.forEach(table => {
        content.add('        /// <summary>')
        if(table.comment){
            content.add(`        /// ${table.name}(${table.comment})表的实体`)
        }
        else{
            content.add(`        /// ${table.name}表的实体`)
        }
        content.add('        /// </summary>')
        if(table.relationType == '2'){
            content.add(`        public IEnumerable<${window.$upFirst(`${table.className}Entity`)}> ${window.$upFirst(`${table.className}List`)} { get; set; }`)
        }
        else{
            content.add(`        public ${window.$upFirst(`${table.className}Entity`)} ${window.$upFirst(`${table.className}Entity`)} { get; set; }`)
        }

        
    })
    strCode = content.writeTo(strCode,'ClassContent')
    
    

    return strCode
}